{% extends "djdb/internal_page.html" %}

{% load common_extras %}
{% load djdb_extras %}

{% block breadcrumbs %}
<a href="/">chipradio home</a>
{% endblock %}

{% block content %}

{% block extrahead %}
<script type="text/javascript" 
    src="/media/common/js/jquery/jquery-1.3.1.js"></script>
<script type="text/javascript" 
    src="/media/common/js/jquery-autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript" src="/media/djdb/js/djdb.js"></script>
<script type="text/javascript" src="/media/djdb/js/djdb_user.js"></script>
<script type="text/javascript" src="/media/djdb/js/djdb_search_help.js"></script>
{% endblock %}

{% if msg %}
<div class="success">
{{ msg }}
</div>
{% endif %}

{% if not query_str %}
<h2>Browse the Database</h2>

<h3>
By: [
<a href="/djdb/browse/artist/all">Artist</a> |
<a href="/djdb/browse/album/all">Album</a> |
<a href="/djdb/browse/track/all">Track</a>
]
<br/>

Category: [
  {% for category in categories %}
    {% if not forloop.first %} | {% endif %}
<a href="/djdb/browse/album/all?category={{ category }}">{{ category|replace:"/_/ "|capfirst }}</a>
  {% endfor %}
]
<br/>

Starts with: [
<a href="/djdb/browse/artist/all">All</a> |
<a href="/djdb/browse/artist/0">0-9</a> |
  {% for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' %}
<a href="/djdb/browse/artist/{{ letter }}">{{ letter }}</a> |
  {% endfor %}
<a href="/djdb/browse/artist/other">Other</a>
]
</h3>
<form method="post" action="/djdb/browse/album/random">
    <input type="submit" name="RandomAlbums" value="Fetch Random Albums"/>
</form>
{% endif %}

<h2>Search the Database</h2>
<form action="" method="post">
  <input type="text" name="query"/>
  <input type="submit" value="Search"/>
  <input type="checkbox" name="reviewed"/>&nbsp;Reviewed
  By
  <input id="id_user" name="user"/>
  <input id="id_user_key" type="hidden" name="user_key"/>
</form>
<a href="">Advanced</a>
| <a class="open_search_help" href="">Help with searching...</a>
<div class="search_help" style="display: none">
<p>
[ <a class="close_search_help" href="">Close</a> ]
</p>

<p>
<u><b>Search Help</b></u>
</p>

<p>
Our query language is very simple. Here are some illustrative examples:
</p>

<p>
<ol>
  <li>"foo bar" means find all entities whose text contains both the terms "foo" and "bar".</li><br/>
  
<li>"-foo" means exclude all entities whose text contains the term "foo".</li><br/>
  <li>"foo*" means find all entities whose text contains a term starting with the prefix "foo".</li><br/>
  <li>"field:blah" means find all entities whose given field contains the term "blah". The field may be one of the following: name, title, year, or tag.</li><br/>
  <li>"field:blah*" means find all entities whose given field conains a term starting with the prefix "blah".</li><br/>
  <li>"field:start-end" means find all entities whose given field (e.g., year) falls within the range "start" to "end".</li>
</ol>
</p>

<p>
[ <a class="close_search_help" href="">Close</a> ]
</p>
</div>
<p/>

{% if query_str %}
<h2>Query: "{{ query_str }}"
  {% if invalid_query %}<br/><b>Invalid Query!</b>{% endif %}
</h2>

<h3>Artists</h3>
<i>{{ query_results.Artist|length }}
matching artist{{ query_results.Artist|pluralize }}</i><br/>

  {% if query_results.Artist %}
<table>
    {% for artist in query_results.Artist %}
      {% if artist.revoked %}
  <tr class="revoked">
      {% else %}
  <tr>
      {% endif %}
    <td><a href="{{ artist.url }}">{{ artist.pretty_name }}</a></td>
    <td>{{ artist.num_albums }} album{{ artist.num_albums|pluralize }}</td>
    <td>
      {% ifincrate user artist %}
      <a href="/djdb/crate/remove_item?response_page=landing&item_key={{ artist.key }}&query={{ query_str }}"><img src="/media/common/img/remove.png" alt="Remove Artist from Crate" title="Remove Artist from Crate"/></a>
      {% else %}
      <a href="/djdb/crate/add_item?response_page=landing&item_key={{ artist.key }}&query={{ query_str }}"><img src="/media/common/img/add.png" alt="Add Artist to Crate" title="Add Artist to Crate"/></a>
      {% endifincrate %}
    </td>
      {% if user.is_music_director %}
      <td>
        {% if artist.revoked %}
        <a href="/djdb/artist/{{ artist.name }}/unrevoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/unrevoke_icon.png" alt="Unrevoke artist"/></a>
        {% else %}
        <a href="/djdb/artist/{{ artist.name }}/revoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/revoke_icon.png" alt="Revoke artist"/></a>
        {% endif %}
      </td>
      {% endif %}
  </tr>
    {% endfor %}
</table>
  {% endif %}

<h3>Albums</h3>
<i>{{ query_results.Album|length }}
matching album{{ query_results.Album|pluralize }}</i>

  {% if query_results.Album %}
    {% if user.is_music_director %}
<form method="post" name="djdbForm" action="/djdb/update_albums">
<p/>
Select: <a id="select_all" href="">All</a>,
        <a id="select_none" href="">None</a>,
      {% for category in categories %}
        {% if not forloop.first %}, {% endif %}
        <a id="select_{{ category }}" href="">{{ category|replace:"/_/ "|capfirst }}</a>
      {% endfor %}<br/>
Mark/Unmark selected as:
      {% for category in categories %}
        {% if not forloop.first %}, {% endif %}
        <a id="mark_{{ category }}" href="/djdb/update_albums">{{ category|replace:"/_/ "|capfirst }}</a>
      {% endfor %}
<p/>
    {% endif %}

    {% if user.is_music_director %}
  <input type="hidden" name="mark_as"/>
  <input type="hidden" name="query" value="{{ query_str }}"/>
    {% endif %}
  <table>
    {% for album in query_results.Album %}
      {% if album.revoked %}
    <tr class="revoked">
      {% else %}
    <tr>
      {% endif %}
      {% if user.is_music_director %}
      <td>
        <input type="checkbox" class="checkbox
        {% for tag in album.current_tags %}
          {% if tag in categories %}
            {{ tag }}
          {% endif %}
        {% endfor %}"
               name="checkbox_{{ forloop.counter }}"/>
        <input type="hidden" name="album_key_{{ forloop.counter }}" value="{{ album.key }}"/>
      </td>
      {% endif %}
      <td>
      {% for tag in album.current_tags %}
        {% if tag in categories %}
        <div class="track_{{ tag }}">{{ tag|replace:"/_/ "|capfirst }}</div>
        {% endif %}
      {% endfor %}
      </td>
      <td><a href="{{ album.artist_url}}">{{ album.artist_name }}</a></td>
      <td><a href="{{ album.url }}">{{ album }}</a></td>
      <td>
      {% ifnotequal album.label None %}
      {{ album.label }}
      {% endifnotequal %}
      </td>
      <td>
      {% ifnotequal album.year None %}
      {{ album.year }}
      {% endifnotequal %}
      </td>
      <td>
      {% if album.num_reviews %}
      {{ album.num_reviews }} review{{ album.num_reviews|pluralize }}
      {% endif %}
      </td>
      <td>
      {% ifincrate user album %}
        <a href="/djdb/crate/remove_item?response_page=landing&item_key={{ album.key }}&query={{ query_str }}"><img src="/media/common/img/remove.png" alt="Remove Album from Crate" title="Remove Album from Crate"/></a>
      {% else %}
        <a href="/djdb/crate/add_item?response_page=landing&item_key={{ album.key }}&query={{ query_str }}"><img src="/media/common/img/add.png" alt="Add Album to Crate" title="Add Album to Crate"/></a>
      {% endifincrate %}
      </td>
      {% if user.is_music_director %}
      <td>
        {% if not album.is_compilation and not album.album_artist.revoked %}
          {% if album.revoked %}
        <a href="/djdb/album/{{ album.album_id }}/unrevoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/unrevoke_icon.png" alt="Unrevoke album"/></a>
          {% else %}
        <a href="/djdb/album/{{ album.album_id }}/revoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/revoke_icon.png" alt="Revoke album"/></a>
          {% endif %}
        {% endif %}
      </td>
      {% endif %}
    </tr>
    {% endfor %}
  </table>
    {% if user.is_music_director %}
</form>
    {% endif %}
  {% endif %}

<h3>Tracks</h3>
<i>{{ query_results.Track|length }}
matching track{{ query_results.Track|pluralize }}</i>
  {% if query_results.Track %}
<table>
    {% for track in query_results.Track %}
      {% if track.revoked %}
  <tr class="revoked">
      {% else %}
  <tr>
      {% endif %}
    <td>{{ track.title }}</td>
    <td><a href="{{ track.artist_url }}">{{ track.artist_name }}</a></td>
    <td><a href="{{ track.album.url }}">{{ track.album }}</a></td>
    <td>
      <a class="send_to_playlist" href="/djdb/crate/send_to_playlist/{{ track.key }}"><img src="/media/common/img/play.png" alt="Send to Playlist" title="Send to Playlist"/></a>    
    </td>
    <td>
      {% ifincrate user track %}
      <a href="/djdb/crate/remove_item?response_page=landing&item_key={{ track.key }}&query={{ query_str }}"><img src="/media/common/img/remove.png" alt="Remove Track from Crate" title="Remove Track from Crate"/></a>
      {% else %}
      <a href="/djdb/crate/add_item?response_page=landing&item_key={{ track.key }}&query={{ query_str }}"><img src="/media/common/img/add.png" alt="Add Track to Crate" title="Add Track to Crate"/></a>
      {% endifincrate %}
    </td>
    {% if user.is_music_director %}
    <td>
      {% if not track.album.revoked %}
        {% if track.revoked %}
      <a href="/djdb/track/{{ track.key }}/unrevoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/unrevoke_icon.png" alt="Unrevoke track"/></a>
        {% else %}
      <a href="/djdb/track/{{ track.key }}/revoke?response_page=landing&query={{ query_str }}"> <img src="/media/common/img/revoke_icon.png" alt="Revoke track"/></a>
        {% endif %}
      {% endif %}
    </td>
    {% endif %}
  </tr>
    {% endfor %}
</table>
  {% endif %}
{% endif %}

{% if not query_str %}
<h2>Recent Activity</h2>
  {% if activity_incomplete %}
  <p>
  <i><b>This list of recent activity is incomplete.</b></i> <a href="/djdb/activity">See all recent activity...</a>
  </p>
  {% endif %}
  {% for dt, items in recent_activity %}
{{ dt|date:"D F j, Y P" }}
<ul class="activity">
    {% for type, item in items %}
  <li class="activity_{{ type }}">{{ item|safe }}</li>
    {% endfor %}
</ul>
  {% endfor %}

<a href="/djdb/activity">See more recent activity...</a>
{% endif %}

{% endblock %}
